<?php

class validateCode extends AbstructApp {
	public function todo(){
		echo __METHOD__;
	}
	
	public function valid(){
	}

	public function def(){
		header ("Content-type: image/png");
		$im = @imagecreatetruecolor(90, 20)
		      or die("Cannot Initialize new GD image stream");
		$color = imagecolorallocate($im, 255, 255, 255);
		$str = $this->getValidStr(); 
		$font = "html/images/simsun.ttc";
		$glines = rand(5,10);
		for($i=$glines;$i>=0;$i--)
		{
			$lineColor = imagecolorallocate($im, rand(80,255), rand($i,$i+30),rand($i,$i+30));
			imageline($im, rand(0,100), rand(0,100), rand(0,34), rand(0,34), $lineColor);
		}
		$x = 5;
		for($i=0;$i<strlen($str);$i++)
		{
			$x += 10;
			$y = 17;
			$z = rand(210,225);
			$color = imagecolorallocate($im, rand(210,255), rand($z,$z-30),rand($z,$z+30));
			ImageTTFText($im, 13, 10, $x,$y, $color, $font, $str[$i]); 
		}
		imagepng($im);
		imagedestroy($im);		
	}
	
	private function getValidStr()
	{
		$a1 = ord('a');
		$a2 = ord('z');
		$b1 = ord('A');
		$b2 = ord('Z');
		$c1 = ord('0');
		$c2 = ord('9');
		$array = array('c');
		$validStr = "";
		for($i=0;$i<6;$i++)
		{
			$v = array_rand($array);
			$k = $array[$v];
			eval("\$mixV = \$".$k."1;");
			eval("\$maxV = \$".$k."2;");
			$validStr .= chr(rand($mixV,$maxV));
		}
		$valid = _cfg::sessionPrefix."_valid";
		//$validStr = _cfg::validForceCase?$validStr:strtolower($validStr);
		$_SESSION[$valid]=array(
			"time" => time(),
			"str"  => $validStr,
			"remoter"	=>	$_SERVER[REMOTE_ADDR]
		);
		return $validStr;
		
	}	
}


return md5(__FILE__);